import UnionFind from '../../../src/datastructure/unionfind/UnionFind'
import UnionFind2 from '../../../src/datastructure/unionfind/UnionFind2'
import UnionFind3 from '../../../src/datastructure/unionfind/UnionFind3'

/* const uf1 = new UnionFind(10)
console.log(uf1.isConnected(0, 1))
uf1.unionElements(0, 1)
console.log(uf1.isConnected(0, 1))
uf1.unionElements(1, 9)
uf1.unionElements(1, 8)
console.log(uf1.isConnected(8, 9))

const uf2 = new UnionFind2(10)
console.log(uf2.isConnected(0, 1))
uf2.unionElements(0, 1)
console.log(uf2.isConnected(0, 1))
uf2.unionElements(1, 9)
uf2.unionElements(1, 8)
console.log(uf2.isConnected(8, 9))

const uf3 = new UnionFind3(10)
console.log(uf3.isConnected(0, 1))
uf3.unionElements(0, 1)
console.log(uf3.isConnected(0, 1))
uf3.unionElements(1, 9)
uf3.unionElements(1, 8)
console.log(uf3.isConnected(8, 9)) */

/**
 * generate [0,range) integer
 * @param range
 * @returns {number}
 */
function randomInt (range) {
  return Math.floor(Math.random() * range)
}

function testUnionFind (uf, count) {
  const size = uf.getSize()
  console.time('uf')
  for (let i = 0; i < count; i++) {
    const a = randomInt(size)
    const b = randomInt(size)
    uf.unionElements(a, b)
  }
  for (let i = 0; i < count; i++) {
    const a = randomInt(size)
    const b = randomInt(size)
    uf.isConnected(a, b)
  }
  console.timeEnd('uf')
}

const counts = 1000000
const size = 1000000
testUnionFind(new UnionFind(size), counts)
testUnionFind(new UnionFind2(size), counts)
testUnionFind(new UnionFind3(size), counts)
